require(['swiper', 'common', 'loadmore'], function (Swiper) {
  // 轮播
  var swiper = new Swiper('.gzl-swiper', {
    loop: true,
    speed: 500,
    autoplay: {
      delay: 3000,
      disableOnInteraction: false
    },
    pagination: {
      el: '.swiper-pagination'
    }
  });
  // 导航
  var navItem = $(".small-shop-nav .gzl-navbar__item");
  $(".small-shop-type").css("min-height", $(window).height() - $(".nav-box").height() - $(".gzl-cell__tips").outerHeight())
  if (navItem.length > 5) {
    navItem.parent().addClass("gzl-navbar_auto");
  }
  navItem.on("click", function () {
    var section = $(".gzl-section");
    section.stop().animate({ scrollTop: $(".small-shop-nav").offset().top + section.scrollTop() }, 300)
  });
  var smallNav = new Swiper('.nav-box', {
    slidesPerView: 5,
    autoHeight: true,
    freeMode: true,
    watchSlidesVisibility: true,
    watchSlidesProgress: true
  });
  var smallNavCon = new Swiper('.small-shop-type', {
    autoHeight: true,
    spaceBetween: 12,
    thumbs: {
      swiper: smallNav
    }
  });
  // var smallNavCon = new Swiper('.small-shop-type', {
  //   loop: true,
  //   autoHeight: true,
  //   spaceBetween: 12,
  //   on: {
  //     slideChangeTransitionEnd: function () {
  //       currentIndex = this.realIndex;
  //       console.log(currentIndex)
  //       $(".small-shop-nav li").eq(currentIndex).addClass("active").siblings().removeClass("active");
  //     }
  //   }
  // });
  // $(".small-shop-nav li").on("click", function () {
  //   $(this).addClass('active').siblings().removeClass("active");
  //   smallNavCon.slideTo($(this).index()+1,500)
  // })
  $(".gzl-section").on("scroll", function () {
    var self = this;
    $.requestAnimationFrame(function () {
      var sTop = self.scrollTop;
      var nTop = $(".small-shop-nav").offset().top + sTop;
      if (nTop < sTop) {
        $(".nav-box").addClass("fixed");
        $(".gzl-asidebar .to-top").addClass("show");
      } else {
        $(".nav-box").removeClass("fixed");
        $(".gzl-asidebar .to-top").removeClass("show");
      }
    })
  });
  // 注销提醒
  $.modal({
    text: '店铺已注销，更多精彩请浏览首页',
    buttons: [{
      text: "返回首页",
      onClick: function () {
        console.log("去首页")
      }
    }]
  });
  // toTop
  $(".gzl-asidebar .to-top").on("click", function () {
    $(".gzl-section").animate({ scrollTop: 0 }, 300);
  })
  // 没有更多
  $('.gzl-section').loadend();
});
